package com.mspbots.core.script.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mspbots.core.AbstractBaseController;
import com.mspbots.core.script.model.TenantScript;
import com.mspbots.core.script.service.TenantScriptService;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Callable;


@RestController
@RequestMapping("script")
public class TenantScriptController extends AbstractBaseController<TenantScript, TenantScriptService> {

    @PostMapping("set")
    public Callable init(@RequestParam String systemScript, @RequestParam Long tenantId) {
        return () -> service.updateTenantScript(systemScript, tenantId);
    }


    @Override
    @PostMapping
    public Callable insert(@RequestBody TenantScript entity) {
        return () -> service.saveOrUpdateTenantScript(entity);
    }


    @GetMapping("closereport")
    public Callable closereportallswitch(Long tenantId, Boolean reportSwitch) {
        return () -> service.closeReportAllSwitch(tenantId, reportSwitch);
    }


    @Override
    @GetMapping("page")
    public Callable selectPage(Page<TenantScript> page, TenantScript queryParams) {
        return () -> service.selectBots(page, queryParams);
    }


    @GetMapping("page/escalation")
    public Callable selectEscalation(Long tenantId) {
        return () -> service.selectEscalation(tenantId);
    }

    @Override
    @GetMapping(path = "/list")
    public Callable selectList(TenantScript queryParams) {
        return () -> service.listAndSystemInfo(queryParams);
    }

    @GetMapping(path = "/list/next-ticket")
    public Callable selectList(Long tenantId) {
        return () -> service.getCustomScript(tenantId);
    }

    @GetMapping("findScope")
    public Callable findScope() {
        return () -> service.findScope();
    }

}
